package com.ham.mud.classes;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.characters.Stats;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hlucas on Jun 28, 2011 at 11:43:25 AM
 */
public class MudClassService {
    private static final List<MudClass> classes = new ArrayList<MudClass>();
    static {
        classes.add(new Cleric());
        classes.add(new Mage());
        classes.add(new Thief());
        classes.add(new Warrior());
    }

    public static MudClass getClass(String line) {
        line = line.toLowerCase();

        for(MudClass mudClass : classes) {
            if(mudClass.getName().toLowerCase().equals(line)) {
                try {
                    return mudClass.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }

        return null;
    }

    public static void showClasses(ServerConnection connection) {

        connection.println();
        connection.println("Classes:");
        connection.println("-----------------------------------------");
        connection.println(Colors.getValueAndSpaces(15, "Class") + "| " + "Str Dex Con Int Wis Cha");
        connection.println("-----------------------------------------");

        for(MudClass mudClass : classes) {
            String name = mudClass.getName();
            Stats stats = mudClass.getBaseStats();

            String nameSpace = Colors.getValueAndSpaces(15, name);
            String intSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getIntelligence()), true);
            String strSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getStrength()), true);
            String conSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getConstitution()), true);
            String dexSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getDexterity()), true);
            String chaSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getCharisma()), true);
            String wisSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getWisdom()), true);

            connection.println(nameSpace + "| " + strSpace + " " + dexSpace + " " + conSpace + " " + intSpace + " " + wisSpace + " " + chaSpace);
        }

        connection.println("-----------------------------------------");
    }
}
